package org.mashibing.controller;

import org.mashibing.dto.ResponseResult;
import org.mashibing.request.VerificationCodeDTO;
import org.mashibing.response.NumberCodeResponse;
import org.mashibing.response.TokenResponse;
import org.mashibing.service.VerificationCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:
 * @create: 2024/3/20 10:31
 * @description: 乘客验证码
 */
@RestController
public class VerificationCodeController {

    @Autowired
    private VerificationCodeService verificationCodeService;

    /**
     * 用户获取数字验证码
     */
    @GetMapping("/verification-code")
    public ResponseResult<NumberCodeResponse> verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        //获取乘客手机号
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        return verificationCodeService.generatorCode(passengerPhone,6);
    }

    /**
     * 乘客检验验证码
     */
    @PostMapping("/verification-code-check")
    public ResponseResult<TokenResponse> checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        //获取乘客手机号、验证码
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        String verificationCode = verificationCodeDTO.getVerificationCode();

        return verificationCodeService.checkCode(passengerPhone,verificationCode);
    }


}
